home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Catalog Service Access Module / DTS Sample CSAM / Src / MPWDriverGlue.a < prev    next >
Encoding:
Text File  |  1993-06-24  |  4.1 KB  |  137 lines  |  [TEXT/MPS ]

  1. *
  2. * DriverGlue.a
  3. * Copyright © 1992, Apple Computer Inc., All Rights Reserved.
  4. *
  5. * This file contains the MPW driver header that will be used to
  6. * connect our device driver to the Macintosh O.S. Device Manager.
  7. * Note that it is a generic driver header file: you can use
  8. * this for any device driver.
  9. *
  10. * This must be the first module in the Link input specifier.
  11. *
  12. * Your driver must provide the following functions (globalized):
  13. *
  14. *    OSErr        OpenDRVR(
  15. *        CntrlParam        *paramBlock,
  16. *        DCtlPtr            devCtlEnt
  17. *    );
  18. *    OSErr        CloseDRVR(
  19. *        CntrlParam        *paramBlock,
  20. *        DCtlPtr            devCtlEnt
  21. *    );
  22. *    OSErr        PrimeDRVR(
  23. *        CntrlParam        *paramBlock,
  24. *        DCtlPtr            devCtlEnt
  25. *    );
  26. *    OSErr        ControlDRVR(
  27. *        CntrlParam        *paramBlock,
  28. *        DCtlPtr            devCtlEnt
  29. *    );
  30. *    OSErr        StatusDRVR(
  31. *        CntrlParam        *paramBlock,
  32. *        DCtlPtr            devCtlEnt
  33. *    );
  34. *
  35. * This file is compiled by MPW and linked with the actual driver C
  36. * source files. It is not used when the driver is compiled by Think C.
  37. *
  38. * Author:        Martin Minow
  39. *                Apple Computer Inc.
  40. *                Cupertino, CA, USA
  41. * InterNet:        minow@apple.com
  42. * AppleLink:    MINOW
  43. *
  44.             print        push,off            ; Don't waste paper
  45.             include        'SysEqu.a'
  46.             include        'SysErr.a'
  47.             include        'Traps.a'
  48.             include        'DriverGlue.incl.a'    ; MacsBug name macro
  49.             print        pop                    ; Restore print options
  50.             case        obj
  51. *
  52. * Define the external functions that DriverGlue must call.
  53. *
  54. DriverGlue    proc        export
  55. *
  56. * External definitions
  57. *
  58.             import        OpenDRVR
  59.             import        PrimeDRVR
  60.             import        ControlDRVR
  61.             import        StatusDRVR
  62.             import        CloseDRVR
  63. *
  64. * This module must be compiled as a 'DRVW' id=0 resource. Rez will
  65. * append this to the 'DRVR' resource that contains the driver header
  66. * data.
  67. *
  68. * The following is an interface between the Device Manager driver call
  69. * and the C function that performs the actual operation. It saves
  70. * registers, then builds a C parameter block that contains the
  71. * parameter block pointer and the driver control entry parameter
  72. * block pointer and calls the C function. Note that this driver
  73. * glue uses a standard C calling sequence. It might be slightly
  74. * more advantageous to use the pascal call sequence as the user
  75. * could write the handler function in either C or Pascal. However,
  76. * I also want to show how driver glue can be written using Think C
  77. * asm statements, so we're stuck with C glue. We build a complete
  78. * stack frame to simplify debugging trace backs.
  79. *
  80. * The driver glue handler performs three basic functions:
  81. * 1.    It saves registers and builds a C parameter block on the stack.
  82. * 2.    After the C handler returns, it test the immediate bit in
  83. *        the trap word and returns directly if it was set.
  84. * 3.    If the C function returns 1 (I/O in progress), it returns directly.
  85. *        Otherwise, it the operation has completed, so the function exits
  86. *        to the device manager via jIODone.
  87. *
  88.             seg            'Main'
  89.             export        main
  90. main        bra.s        openGlue
  91.             nop                                    ; For DRVR offset
  92.             bra.s        primeGlue
  93.             nop                                    ; For DRVR offset
  94.             bra.s        controlGlue
  95.             nop                                    ; For DRVR offset
  96.             bra.s        statusGlue
  97.             nop                                    ; For DRVR offset
  98. closeGlue    pea            CloseDRVR
  99.             bra.s        common
  100. openGlue    pea            OpenDRVR
  101.             bra.s        common
  102. primeGlue    pea            PrimeDRVR
  103.             bra.s        common
  104. controlGlue    pea            ControlDRVR
  105.             bra.s        common
  106. statusGlue    pea            StatusDRVR
  107. *            bra.s        common
  108. *
  109. *
  110. common        move.l        (a7)+,d0                ; The function to call
  111.             link        a6,#0                    ; Establish a stack frame
  112.             movem.l        d1-d3/a0-a4,-(a7)        ; Save registers
  113.             move.l        a1,-(a7)                ; Push DCE Ptr on the stack
  114.             move.l        a0,-(a7)                ; Push ParamBlockPtr on the stack
  115.             move.l        d0,a0                    ; Get the function to call
  116.             jsr            (a0)                    ; Call handler, result in d0
  117.             addq.w        #8,a7                    ; Clear parameters from stack
  118.             movem.l        (a7)+,d1-d3/a0-a4        ; Restore registers
  119.             btst        #noQueueBit,ioTrap(a0)    ; Is noQueueBit set?
  120.             bne.s        exit                    ; Branch if so
  121.             cmp.w        #1,d0                    ; C result "incomplete"?
  122.             beq.s        exit                    ; Branch if so
  123.             unlk        a6                        ; I/O complete, clear linkage
  124.             move.l        jIODone,-(a7)            ; Return via jIODone
  125.             rts                                    ; Exit the driver glue
  126. *
  127. exit        unlk        a6                        ; Destroy the linkage
  128.             rts                                    ; Exit to the caller
  129.             DbgInfo        DriverGlue
  130.             endp
  131. *
  132. * That's all folks.
  133. *
  134.             end
  135.  
  136.             
  137.